home *** CD-ROM | disk | FTP | other *** search
- /* XGStdStaticText.cpp
- *
- * this is my internal implementation of a static text object.
- * This is something I simply roll myself
- */
-
- /* YAAF - Yet another application framework
- * Copyright (C) 1997 William Edward Woody and In Phase Consulting
- *
- * This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Library
- * General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or any
- * later version.
- *
- * This library is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Library General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Library General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * To contact the author, either e-mail me at
- * woody@alumni.caltech.edu, or write to us at
- *
- * William Edward Woody
- * In Phase Consulting
- * 1545 Ard Eevin Avenue
- * Glendale, CA 91202
- */
-
- #include <string.h>
- #include <XError.h>
- #include <XStdText.h>
- #include <XApplication.h>
- #include <XStdControls.h>
- #include <XDataUtil.h>
-
- /************************************************************************/
- /* */
- /* Construction/Destruction */
- /* */
- /************************************************************************/
-
- /* XGStdStaticText::XGStdStaticText
- *
- * Initialize me
- */
-
- XGStdStaticText::XGStdStaticText(XGView *v, XGArgStream &s) :
- XGStdText(v,s,true)
- {
- char buffer[256];
- s.GetString(sizeof(buffer),buffer);
- Init(buffer);
- }
-
- XGStdStaticText::XGStdStaticText(XGView *v, XGSTextInitRecord &s) :
- XGStdText(v,s.v,true)
- {
- Init(s.text);
- }
-
- /* XGStdStaticText::~XGStdStaticText
- *
- * Delete me
- */
-
- XGStdStaticText::~XGStdStaticText()
- {
- }
-
- /************************************************************************/
- /* */
- /* Text Drawing */
- /* */
- /************************************************************************/
-
- /* XGStdStaticText::GetText
- *
- * Get the text contents of this
- */
-
- void XGStdStaticText::GetText(char *text)
- {
- #if OPT_MACOS == 1
- strcpy(text,fString.Get());
- #endif
-
- #if OPT_WINOS == 1
- ::GetWindowText(_GetHWND(),text,256);
- #endif
- }
-
- /* XGStdStaticText::SetText
- *
- * Set the text and force a redraw
- */
-
- void XGStdStaticText::SetText(char *text)
- {
- #if OPT_MACOS == 1
- fString = text;
- #endif
-
- #if OPT_WINOS == 1
- ::SetWindowText(_GetHWND(),text);
- #endif
-
- InvalView();
- }
-
- /************************************************************************/
- /* */
- /* Static Control Drawing */
- /* */
- /************************************************************************/
-
- /* XGStdStaticText::DoDrawView
- *
- * Draw this thing
- */
-
- void XGStdStaticText::DoDrawView(Rect)
- {
- #if OPT_MACOS == 1
- XGDraw draw(this);
- Rect r;
- const char *text = fString.Get();
-
- r = GetContentRect();
-
- ::TextFont(fFont);
- ::TextSize(fSize); // request my current font
- ::EraseRect(&r);
- ::TETextBox(text,strlen(text),&r,teFlushDefault);
- #endif
- }
-
- /************************************************************************/
- /* */
- /* Static Control Drawing */
- /* */
- /************************************************************************/
-
- /* XGStdStaticText::Init
- *
- * This handles the initialization
- */
-
- void XGStdStaticText::Init(char *buffer)
- {
- long l;
-
- l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);
- #if OPT_MACOS == 1
- fFont = GETHIWORD(l);
- fSize = GETLOWORD(l);
- fString = buffer;
- #endif
-
- #if OPT_WINOS == 1
- Rect r;
- HWND w;
-
- /*
- * Get the location of the control in the parent's coordinate
- * system
- */
-
- r = GetContentRect();
- if (GetParent()) {
- ViewToGlobal(&r);
- GetParent()->GlobalToView(&r);
- }
-
- /*
- * Create the control window
- */
-
- w = CreateWindow("EDIT", // control class
- buffer, // control title
- WS_CHILD | ES_AUTOHSCROLL | // control window flags
- ES_READONLY,
- r.left,
- r.top,
- r.right-r.left,
- r.bottom-r.top, // control location
- GetParent()->_GetHWND(), // container window
- NULL, // no menu
- _GInstance, // My app instance
- NULL); // no additional args
- if (w == NULL) {
- throw XPostError("Unable to make display box");
- }
-
- _SetHWND(w); // set me as the window
- SetProp(w,_GViewClass,(HANDLE)this);
- if (IsVisible()) ShowWindow(w,SW_SHOW);
- EnableWindow(w,IsEnabled()); // set me up
- #endif
- }
-
-